<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ec</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-descriptions title="用户信息">
        <el-descriptions-item label="用户名">{{user.user_name}}</el-descriptions-item>
        <el-descriptions-item label="权限">{{user.authorities}}</el-descriptions-item>
        <el-descriptions-item label="应用id">
            <el-tag size="small">{{user.client_id}}</el-tag>
        </el-descriptions-item>
    </el-descriptions>
    <el-button @click="logout()">退出登录</el-button>
</div>
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                user: {}
            }
        },
        created() {
            let accessToken = sessionStorage.getItem('access_token');
            if (accessToken) {//已登录
                //已登录获取用户信息
                let paload = accessToken.split(".")[1];
                this.user = JSON.parse(decodeURIComponent(escape(window.atob(paload))));
            } else {
                //未登录
                this.login();
            }
        },
        methods: {
            logout() {
                this.$confirm('确认退出?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //todo 退出处理
                    this.$message({
                        type: 'warning',
                        message: '退出功能未开发'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消登录'
                    });
                });
            },
            login() {
                sessionStorage.setItem("visitUri", window.location.href);
                window.location = 'http://127.0.0.1:8080/oauth/authorize?client_id=ec&response_type=code&redirect_uri=http://127.0.0.1:9011/callback.html';
            }
        }
    })
</script>
</body>
</html>